package com.example.administrator.newsapp.AdapterManagers;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.newsapp.Datas.Channel;
import com.example.administrator.newsapp.R;
import com.example.administrator.newsapp.ViewHoders.GridHolder;
import com.example.administrator.newsapp.ViewHoders.GridHolder2;
import com.example.administrator.newsapp.ViewHoders.ListHolder;

import java.util.Date;
import java.util.List;

public class MyAdapter extends RecyclerView.Adapter {
    private List<Channel> list;
    private Context context;
    private LayoutInflater inflater;

    public MyAdapter(List<Channel> list, Context context) {
        this.list = list;
        this.context = context;
        this.inflater = LayoutInflater.from(context);
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view;
        RecyclerView.ViewHolder holder=null;
        if (i==1){
            view=inflater.inflate(R.layout.linearview,null);
            holder=new ListHolder(view);
        }else if (i==2){
            view=inflater.inflate(R.layout.linearview2,null);
            holder=new ListHolder(view);
        }else if (i==3){
            view=inflater.inflate(R.layout.gridview_true,null);
            holder=new GridHolder(view);
        }else if(i==4){
            view=inflater.inflate(R.layout.gridview_false,null);
            holder=new GridHolder2(view);
        }
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        switch (getItemViewType(i)){
            case 1:
                ListHolder listHolder=(ListHolder) viewHolder;
                listHolder.tv_title.setText(list.get(i).channel_title);
                listHolder.tv_title_words.setText(list.get(i).channel_words);
                break;
            case 2:
                ListHolder listHolder2=(ListHolder) viewHolder;
                listHolder2.tv_title.setText(list.get(i).channel_title);
                listHolder2.tv_title_words.setText(list.get(i).channel_words);
                break;
            case 3:
                GridHolder gridHolder=(GridHolder)viewHolder;
                gridHolder.bt_name.setText(list.get(i).channer_name);
                break;
            case 4:
                GridHolder2 gridHolder2=(GridHolder2)viewHolder;
                gridHolder2.tv_name.setText(list.get(i).channer_name);
                break;
        }
    }

    @Override
    public int getItemViewType(int position) {
        return list.get(position).type;
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
}
